package com.yishe.controller.tech.userinfo;

import com.yishe.biz.tech.userinfo.StaffBiz;
import com.yishe.config.ObjectRestResponse;
import com.yishe.entites.mysql.YsStaff;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author : chusifeng
 * @version :
 * @date :Create in 2021/4/21 17:07
 * @description: 员工信息
 * @package com.yishe.controller.tech.userinfo
 * @className StaffController
 */
@RestController
@Slf4j
@RequestMapping(value = "/tech/userinfo")
public class StaffController {
    @Resource
    private StaffBiz staffBiz;

    @GetMapping
    @RequestMapping("deleteStaff")
    public ObjectRestResponse deleteStaff(@RequestParam("account") String account) {
        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            staffBiz.deleteStaff(account);
        } catch (Exception e) {
            log.info("删除员工失败",e);
            restResponse.setErrorMsg("删除失败！");
        }
        return restResponse;
    }

    @PostMapping
    @RequestMapping("saveStaff")
    public ObjectRestResponse saveStaff(@RequestBody YsStaff ysStaff) {
        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            staffBiz.saveStaff(ysStaff);
        } catch (Exception e) {
            log.info("保存员工信息失败",e);
            restResponse.setErrorMsg("删除失败！");
        }
        return restResponse;
    }
    @GetMapping
    @RequestMapping("getStaffInfo")
    public ObjectRestResponse getStaffInfo(@RequestParam("account") String account) {
        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
           restResponse.setData(staffBiz.getStaffInfo(account));
        } catch (Exception e) {
            log.info("获取员工信息失败",e);
            restResponse.setErrorMsg("删除失败！");
        }
        return restResponse;
    }
}
